/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "ODE核心.h"


#ifdef _DEBUG 
#pragma comment(lib,"D:/U/DEV/ODE/lib/debug/ode_doubled.lib")
#else
#pragma comment(lib,"D:/U/DEV/ODE/lib/Release/ode_double.lib")
#endif



#include <矩阵.h>





S_ODE核心::S_ODE核心()
{
	dInitODE2(0);
	m_物理世界 = dWorldCreate();
	m_物理空间 = dHashSpaceCreate(0);
	//contactgroup = dJointGroupCreate(0);
	dWorldSetGravity(m_物理世界, 0, -9.8, 0);
	dWorldSetCFM(m_物理世界, 1e-5);
	dWorldSetAutoDisableFlag(m_物理世界, 1);

	dWorldSetLinearDamping(m_物理世界, 0.00001);
	dWorldSetAngularDamping(m_物理世界, 0.005);
	dWorldSetMaxAngularSpeed(m_物理世界, 200);

	dWorldSetContactMaxCorrectingVel(m_物理世界, 0.1);
	dWorldSetContactSurfaceLayer(m_物理世界, 0.001);


	m_线程ID = dThreadingAllocateMultiThreadedImplementation();
	m_线程池ID = dThreadingAllocateThreadPool(16, 0, dAllocateFlagBasicData, NULL);
	dThreadingThreadPoolServeMultiThreadedImplementation(m_线程池ID, m_线程ID);
	// dWorldSetStepIslandsProcessingMaxThreadCount(world, 1);
	dWorldSetStepThreadingImplementation(m_物理世界, dThreadingImplementationGetFunctions(m_线程ID), m_线程ID);

	dCreatePlane(m_物理空间, 0, 0, 1, 0);
}

S_ODE核心::~S_ODE核心() {
	// run simulation
	//dsSimulationLoop(argc, argv, DS_SIMULATION_DEFAULT_WIDTH, DS_SIMULATION_DEFAULT_HEIGHT, &fn);

	dThreadingImplementationShutdownProcessing(m_线程ID);
	dThreadingFreeThreadPool(m_线程池ID);
	dWorldSetStepThreadingImplementation(m_物理世界, NULL, NULL);
	dThreadingFreeImplementation(m_线程ID);

	//dJointGroupDestroy(contactgroup);
	dSpaceDestroy(m_物理空间);
	dWorldDestroy(m_物理世界);
	dCloseODE();

}
